<template>
  <view class="app-sider">
   <view class="" style=" flex: 1;
      overflow: hidden;padding:20px 0; box-sizing: border-box;">
     <scroll-view scroll-y="true" style="height: 100%; width: 100%">
       <view class="logo">
         <image
           src="https://hongwu-1318589231.cos.ap-guangzhou.myqcloud.com/dongyuan/default/2025/08/05/ed7060dca37b43c69c30f1bf01ffd1862kQWewJbJ4wK15a011c3306944a3f3930bda80f44534.png"
           mode="widthFix" style="width: 80px; height: 40px"></image>
       </view>
       <view class="menus">
         <view class="item" v-for="item in menus" :class="{ active: activeTab === item.key }" @click="tabClick(item)"
           :key="item.key">
           <view>
             <image style="width: 56px; height: 56px" mode="widthFix"
               :src="activeTab === item.key ? item.icon_ : item.icon"></image>
           </view>
           <view>{{ item.name }}</view>
         </view>
       </view>
     </scroll-view>
   </view>
    <view class="user-info">
      <image src="/static/imgs/avatar1.png" mode="" class="info-log"></image>
      <text class="info-name">{{ userInfo.user.nickName }}</text>
      <view class="logout">
        <text @click="logout">退出</text>
        <image src="@/static/icons/logout.png" mode="widthFix" @click="logout"></image>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import { menus } from './config'
  import { useUser } from '@/stores/modules/user'
  import { useSysInfo } from '@/stores/modules/sysInfo'
  const { userInfo } = useUser()
  const props : any = defineProps({
    pageKey: String,
  })

  let { activeTab, setActiveTab } = useUser()
  activeTab = props.pageKey
  setActiveTab(props.pageKey)
  const tabClick = (item) => {
    setActiveTab(item.key)
    if (item.key !== activeTab.value) {
      uni.switchTab({
        url: item.path,
      })
    }
  }

  const logout = () => {
    uni.reLaunch({
      url: '/pages/login/index',
    })
    uni.removeStorageSync('token');
    uni.removeStorageSync('storeInfo');
  }
</script>

<style lang="scss" scoped>
  .app-sider {
    width: 80px;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    text-align: center;
    box-sizing: border-box;
    // padding: 20px 0px;
    box-shadow: inset -1px 0px 0px 0px #e8ecef;
    background-color: #fff;

    .menus {
      flex: 1;
      display: flex;
      flex-direction: column;

      .item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #8590b3;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 12px;

        &.active {
          color: #0f90fd;
        }
      }
    }

    .user-info {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-top: 1px solid #E8ECEF;
      padding: 14px 0;
      box-sizing: border-box;

      .info-log {
        width: 32px;
        height: 32px;
        margin-bottom: 3px;
      }

      .info-name {
        font-weight: 500;
        font-size: 12px;
        color: #8590B3;
        line-height: 17px;
      }

      .logout {
            display: flex;
            align-items: center;
            margin-top:7px;
        text {
          font-weight: 500;
          font-size: 12px;
          color: #8590B3;
        }

        image {
          width: 12px;
          height: 12px;
          margin-left: 8px;
        }
      }
    }
  }
</style>
